import { request } from '@/utils/request';
import Api from '@/core/permission/modules/org/user';

export function getUserListPage(data) {
  return request({
    url: Api.page,
    method: 'post',
    data,
  });
}
export function getUserListPageById(data) {
  return request({
    url: Api.pageByDeptId,
    method: 'post',
    data,
  });
}
export function createUser(data: API.CreateUserParams) {
  return request(
    {
      url: Api.add,
      method: 'post',
      data,
    },
    {
      successMsg: '创建用户成功',
    },
  );
}

export function getUserInfo(query: { username: string | undefined }) {
  return request({
    url: Api.info,
    method: 'get',
    params: query,
  });
}
export function getUserByDepartId(query: { departid: string | undefined }) {
  return request({
    url: Api.pageByDeptId,
    method: 'get',
    params: query,
  });
}

export function updateUser(data) {
  return request(
    {
      url: Api.update,
      method: 'post',
      data,
    },
    {
      successMsg: '修改用户成功',
    },
  );
}

export function beforeAdd(data) {
  return request(
    {
      url: Api.beforeAdd,
      method: 'post',
      data,
    },
  );
}

export function updateUserPassword(data) {
  return request(
    {
      url: Api.password,
      method: 'post',
      data,
    },
    {
      successMsg: '操作成功',
    },
  );
}

export function deleteUsers(data: { id: number }) {
  return request({
    url: Api.delete,
    method: 'post',
    data,
  });
}
